package com.futureway.test.entity;

import java.util.ArrayList;
import java.util.List;

import javax.jdo.annotations.Column;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@AllArgsConstructor
@NoArgsConstructor
@Data
@Table(name = "`order`")
@Entity
public class Order {

	@Id
	@Column(length = 20)
	private String id;

	@Column(length = 100)
	private String orderName;

	@JsonIgnoreProperties(value = "order")
	@OneToMany(mappedBy = "order", cascade = CascadeType.ALL)
	private List<OrderItem> items;

	public void addItem(OrderItem item) {
		this.items = this.items == null ? new ArrayList<>() : this.items;
		this.items.add(item);
		item.setOrder(this);
	}

	public Order(String id, String orderName) {
		super();
		this.id = id;
		this.orderName = orderName;
	}

}
